package com.lmq.chapter02;

public class TernaryIfElse {
    static int ternary(int i) {
        return i < 10 ? i * 100 : i * 10;
    }
    static int standardIfElse(int i) {
        if (i < 10)
            return i * 100;
        else
            return i * 10;
    }
    public static void main(String[] args) {
        System.out.println(ternary(9));
        System.out.println(ternary(10));
        System.out.println(standardIfElse(9));
        System.out.println(standardIfElse(10));

        System.out.println("*****************************");
        int x = 0, y = 1, z = 2;
        String s = "x, y, z ";
        System.out.println(s + x + y + z);
        // Converts x to a String:
        System.out.println(x + " " + s);
        s += "(summed) = "; // Concatenation operator
        System.out.println(s + (x + y + z));
        // Shorthand for Integer.toString():
        System.out.println("" + x);


        System.out.println("*************************");
        int i = 200;
        long lng = (long)i;
        lng = i; // "Widening," so a cast is not required
        long lng2 = (long)200;
        lng2 = 200;
        // A "narrowing conversion":
        i = (int)lng2; // Cast required

        //So the answer is that casting from a float or double to an integral value always
        //truncates the number.
        System.out.println("*************************");
        double above = 0.7, below = 0.4;
        float fabove = 0.7f, fbelow = 0.4f;
        System.out.println("(int)above: " + (int)above);
        System.out.println("(int)below: " + (int)below);
        System.out.println("(int)fabove: " + (int)fabove);
        System.out.println("(int)fbelow: " + (int)fbelow);

        System.out.println(
                "Math.round(above): " + Math.round(above));
        System.out.println(
                "Math.round(below): " + Math.round(below));
        System.out.println(
                "Math.round(fabove): " + Math.round(fabove));
        System.out.println("Math.round(fbelow): " + Math.round(fbelow));

        // Java has no "sizeof"


    }
}
